package com;

import java.util.HashMap;

import javax.servlet.http.HttpSession;

public class MySessionContext {
	private static MySessionContext instance;
	private HashMap<Object, Object> myMap;

	private MySessionContext() {
		myMap = new HashMap<Object, Object>();
	}

	public static MySessionContext getInstance() {
		if (instance == null)
			instance = new MySessionContext();
		return instance;
	}

	public synchronized void addSession(HttpSession session) {
		if (session != null)
			myMap.put(session.getId(), session);
	}
	
	public synchronized void delSession(HttpSession session) {
		if (session != null)
			myMap.remove(session.getId());
	}

	public synchronized HttpSession getSession(String sessionId) {
		if (sessionId == null)
			return null;
		return (HttpSession) myMap.get(sessionId);
	}
}
